<?php
    /**
    * Warning a user when he/she dont active in long time
    * For Pray Online
    * 
    * Note: Permission set on openidmodule, because, loginmodule does not have permission
    */

    if (!defined('EXPONENT')) exit('');

    // check permission first
    $loc=null;
    $loc->mod="openidmodule"; // because, loginmodule does not have permission, so we set permission on openidmodule
    if (exponent_permissions_check("edit_userprofile",$loc) ||
    exponent_permissions_check("administrate",$loc))
    {
        $id=-1;
        if (isset($_REQUEST['user_id']))
        {
            $id=intval($_REQUEST['user_id']);
            $content=$_REQUEST['content'];
            $content=str_replace("\n","<br>",$content);
            $mu=exponent_users_getUserById($id);
            
            // generate email content
            $template = $template = new template("loginmodule","_warning_user_email");
            $template->assign("user",$mu);
            $template->assign("content",$content);
            $html=$template->render();
            ///
            if (!defined('SYS_SMTP')) require_once(BASE.'subsystems/smtp.php');
            @exponent_smtp_mail($mu->email,SITE_TITLE.' <'.SMTP_FROMADDRESS.'>',"Lời nhắn từ ban quản trị " . SITE_TITLE,$html);
            //
            exponent_flow_redirect();
        }
    }
    else
    {
        echo exponent_http_error(403);
    }
?>
